<html>
<head><meta charset="utf-8"><title>being generic over types · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html">being generic over types</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178660971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178660971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178660971">(Oct 21 2019 at 14:35)</a>:</h4>
<p>So I did a lot of exploratory chalk refactoring over the weekend, since I had time to kill in airports while traveling to RBR. My branch is the <a href="https://github.com/nikomatsakis/chalk-ndm/tree/split-tys" target="_blank" title="https://github.com/nikomatsakis/chalk-ndm/tree/split-tys">split-tys</a> branch over on my repository.</p>



<a name="178661001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178661001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178661001">(Oct 21 2019 at 14:35)</a>:</h4>
<p>Current status:</p>
<ul>
<li>the chalk-ir crate includes a <code>TypeFamily</code> trait and all things are generic over this type family</li>
</ul>



<a name="178661023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178661023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178661023">(Oct 21 2019 at 14:35)</a>:</h4>
<ul>
<li>there is one type family (<code>ChalkIr</code>) that all other crates are currently using</li>
</ul>



<a name="178661075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178661075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178661075">(Oct 21 2019 at 14:36)</a>:</h4>
<ul>
<li>the <code>Fold</code> and <code>Zip</code> traits are also generic over the type family</li>
</ul>



<a name="178661112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178661112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178661112">(Oct 21 2019 at 14:36)</a>:</h4>
<p>I started working on the main <em>goal</em> here, which is to make clause generic generic over the "output" type family. It seems to be working "ok" but I decided I wanted to step back a bit from that and first do some other refactorings to that code to clean it up</p>



<a name="178661961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178661961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178661961">(Oct 21 2019 at 14:45)</a>:</h4>
<p>I'm debating how to manage this branch. On the one hand, I kind of think I should land it ASAP -- it's quite invasive and not something I look forward to rebasing.</p>
<p>On the other hand, it doesn't yet reach a "useful" end-goal, and I'm nervous about introducing a lot of generics to the codebase if we decide this is the wrong direction.</p>
<p>On the gripping hand, I feel like 95% confident this <em>is</em> the right direction, and the codebase doesn't (yet) feel a lot more complex.</p>



<a name="178662180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662180">(Oct 21 2019 at 14:47)</a>:</h4>
<p><code>impl&lt;T: Zip&lt;TF&gt;, TF: TypeFamily&gt; Zip&lt;TF&gt; for Vec&lt;T&gt;</code></p>
<p>Interesting, is this indirectly constraining the <code>T</code> by moving the <code>TypeFamily</code> bound to <code>Zip</code> instead?</p>



<a name="178662454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662454">(Oct 21 2019 at 14:51)</a>:</h4>
<p>Merging these changes early doesn't feel like a problem, in the worst case it'll change again later</p>



<a name="178662589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662589">(Oct 21 2019 at 14:52)</a>:</h4>
<blockquote>
<p>On the other hand, it doesn't yet reach a "useful" end-goal</p>
</blockquote>
<p>Do you have something in mind already, or is it more a matter of seeing how it will turn out?</p>



<a name="178662681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662681">(Oct 21 2019 at 14:53)</a>:</h4>
<p>actually, <span class="user-mention" data-user-id="125131">@detrumi</span>, that's a good point; at some point I introducd the <code>HasTypeFamily</code> trait and we could potentially use that instead of having <code>Zip&lt;TF&gt;</code> -- however, it is also useful to sometimes have types (e.g., <code>usize</code> or whatever) that do not belong to any particular type family</p>



<a name="178662752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662752">(Oct 21 2019 at 14:54)</a>:</h4>
<blockquote>
<p>Do you have something in mind already, or is it more a matter of seeing how it will turn out?</p>
</blockquote>
<p>I do definitely have things in mind, in particular I want to use this to change how we do associated type normalization</p>



<a name="178662757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662757">(Oct 21 2019 at 14:54)</a>:</h4>
<p>but I think we can also use it for other things in other codebases</p>



<a name="178662793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662793">(Oct 21 2019 at 14:54)</a>:</h4>
<p>e.g., in the Lark compiler, I used a similar trick to distinguish types that may contain inference variables</p>



<a name="178662799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662799">(Oct 21 2019 at 14:54)</a>:</h4>
<p>from those that cannot</p>



<a name="178662808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662808">(Oct 21 2019 at 14:54)</a>:</h4>
<p>and those that may need substitution</p>



<a name="178662893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662893">(Oct 21 2019 at 14:55)</a>:</h4>
<p>one other thing thing I've found: I think ideally you would have</p>
<div class="codehilite"><pre><span></span><span class="k">trait</span><span class="w"> </span><span class="n">Fold</span><span class="o">&lt;</span><span class="n">TF</span><span class="p">,</span><span class="w"> </span><span class="n">TTF</span><span class="o">&gt;</span><span class="w"></span>
</pre></div>


<p>where <code>TTF</code> is the "target type family" you are folding into</p>



<a name="178662952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662952">(Oct 21 2019 at 14:56)</a>:</h4>
<p>However, lacking higher-ranked generics bounds (e.g., <code>forall&lt;T&gt; { ... }</code>), I was not able to make that work</p>



<a name="178662971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662971">(Oct 21 2019 at 14:56)</a>:</h4>
<p>though I guess if I were willing to give up on <code>Folder</code> being <code>dyn</code>-compatible I might be able to</p>



<a name="178662991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178662991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178662991">(Oct 21 2019 at 14:56)</a>:</h4>
<p>Yeah, that does sound a bit too higher-order for Rust atm</p>



<a name="178663029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178663029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178663029">(Oct 21 2019 at 14:57)</a>:</h4>
<p>( the reason this would matter is that I later had to add some boilerplate, which doesn't show up in the commit history but is true in one of my stashes )</p>



<a name="178663058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178663058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178663058">(Oct 21 2019 at 14:57)</a>:</h4>
<p>( basically reproducing the "Fold" logic but "cross-family" folding )</p>



<a name="178663100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178663100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178663100">(Oct 21 2019 at 14:57)</a>:</h4>
<p>anyway having talked this out a bit I am leaning now towards:</p>
<ul>
<li>land this work which seems good and doesn't change (yet) anything too deep about the existing code</li>
<li>start exploring follow-up work in branches</li>
</ul>



<a name="178663184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178663184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178663184">(Oct 21 2019 at 14:58)</a>:</h4>
<p>landing the work also enables more collaboration. For example, I'd like someone to make a custom derive for <code>Fold</code></p>



<a name="178663191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178663191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178663191">(Oct 21 2019 at 14:58)</a>:</h4>
<p>Right, it does seem to enable further work</p>



<a name="178663200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178663200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178663200">(Oct 21 2019 at 14:58)</a>:</h4>
<p>currently we use <code>macro_rules</code> and it is ungreat</p>



<a name="178663274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178663274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178663274">(Oct 21 2019 at 14:59)</a>:</h4>
<p>procedural macros didn't exist when chalk was first created though and -- at the time -- the macro rules macros were a big win :P</p>



<a name="178702280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178702280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178702280">(Oct 21 2019 at 21:52)</a>:</h4>
<p>opened <a href="https://github.com/rust-lang/chalk/pull/265" target="_blank" title="https://github.com/rust-lang/chalk/pull/265">https://github.com/rust-lang/chalk/pull/265</a></p>



<a name="178702333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178702333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178702333">(Oct 21 2019 at 21:53)</a>:</h4>
<p>I put r? <span class="user-mention" data-user-id="116883">@tmandry</span></p>



<a name="178838713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178838713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178838713">(Oct 23 2019 at 09:56)</a>:</h4>
<blockquote>
<p>I'd like someone to make a custom derive for <code>Fold</code></p>
</blockquote>
<p>I've gotten most of the <code>struct_fold</code> converted to a derive macro already, but this one'll take some work:</p>
<div class="codehilite"><pre><span></span>struct_fold!(impl[TF: TypeFamily, F] Fold&lt;TF&gt; for InEnvironment&lt;F&gt; {
    environment,
    goal,
} where F: HasTypeFamily&lt;TypeFamily = TF&gt; + Fold&lt;TF, Result = F&gt;);
</pre></div>



<a name="178838730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178838730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178838730">(Oct 23 2019 at 09:56)</a>:</h4>
<p><a href="https://github.com/nikomatsakis/chalk-ndm/compare/split-tys...detrumi:fold-derive-macro" target="_blank" title="https://github.com/nikomatsakis/chalk-ndm/compare/split-tys...detrumi:fold-derive-macro">https://github.com/nikomatsakis/chalk-ndm/compare/split-tys...detrumi:fold-derive-macro</a></p>



<a name="178839035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178839035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178839035">(Oct 23 2019 at 10:00)</a>:</h4>
<p>The <code>F</code> corresponds to the <code>G: HasTypeFamily</code> in the struct definition, right? I guess this'll require merging extra generic parameters in, instead of just replacing them like the cases where a non-generic struct had to be impl'd with <code>Fold&lt;ChalkIr&gt;</code></p>



<a name="178839647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178839647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178839647">(Oct 23 2019 at 10:10)</a>:</h4>
<p>For the simpler cases I opted for a <code>#[fold_family(ChalkIr)]</code> attribute on the fold-deriving struct. Not sure if that's the best way, but it seems to work fine</p>



<a name="178852646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178852646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178852646">(Oct 23 2019 at 13:23)</a>:</h4>
<p><code>enum_macro</code> actually was easier to replace (unless I broke something, but the tests are green). <code>Void</code> folding was an edge case but didn't seem to be used, and I don't think the "Hacky variant for use in slg::context::implementation" part of <code>enum_fold</code> was being used either</p>



<a name="178855939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178855939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178855939">(Oct 23 2019 at 13:58)</a>:</h4>
<p><span class="user-mention" data-user-id="125131">@detrumi</span> hmm so --</p>



<a name="178855951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178855951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178855951">(Oct 23 2019 at 13:58)</a>:</h4>
<p>what makes this case different, presumably, is that the type family isn't a direct parameter</p>



<a name="178855958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178855958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178855958">(Oct 23 2019 at 13:58)</a>:</h4>
<p>but is rather "indirected", right?</p>



<a name="178855967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178855967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178855967">(Oct 23 2019 at 13:58)</a>:</h4>
<p>one option would be to say that <code>TypeFamily: HasTypeFamily&lt;TypeFamily = Self&gt;</code></p>



<a name="178855985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178855985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178855985">(Oct 23 2019 at 13:58)</a>:</h4>
<p>so that we could essentially permit the derive on any type with a single type parameter, and then have the template be</p>



<a name="178856017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178856017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178856017">(Oct 23 2019 at 13:59)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">impl</span><span class="o">&lt;</span><span class="n">X</span><span class="p">,</span><span class="w"> </span><span class="n">TF</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Fold</span><span class="o">&lt;</span><span class="n">TF</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">InputType</span><span class="o">&lt;</span><span class="n">X</span><span class="o">&gt;</span><span class="w"></span>
<span class="k">where</span><span class="w"> </span><span class="n">X</span>: <span class="nc">HasTypeFamily</span><span class="o">&lt;</span><span class="n">TypeFamily</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">TF</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">TF</span>: <span class="nc">TypeFamily</span><span class="p">,</span><span class="w"> </span><span class="cm">/* plus where clauses from the type */</span><span class="w"></span>
<span class="p">{</span><span class="w"> </span><span class="p">..</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>



<a name="178856168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178856168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178856168">(Oct 23 2019 at 14:00)</a>:</h4>
<blockquote>
<p>For the simpler cases I opted for a <code>#[fold_family(ChalkIr)]</code> attribute on the fold-deriving struct. Not sure if that's the best way, but it seems to work fine</p>
</blockquote>
<p>hmm yeah I guess we want to cover the cases where there is no type parameter too; really there are a few patterns I suppose. The idea of a supporting attribute is pretty ok</p>



<a name="178856441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178856441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178856441">(Oct 23 2019 at 14:03)</a>:</h4>
<p>I was toying with the idea of detecting the <code>G: HasTypeFamily</code> instead, and then adding a TF parameter in the macro</p>



<a name="178857279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857279">(Oct 23 2019 at 14:12)</a>:</h4>
<p><span class="user-mention" data-user-id="125131">@detrumi</span> yeah, that's another good option -- now that you mention it, I think when I thought about this before, I was imagining:</p>
<ul>
<li>if there is a <code>G: HasTypeFamily</code>, then use that</li>
<li>else if there is a <code>TF: TypeFamily</code>, use that</li>
<li>else we either error or assume this is a copy case that is independent of the TF?</li>
</ul>
<p>it is a bit... sensitive though</p>



<a name="178857290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857290">(Oct 23 2019 at 14:12)</a>:</h4>
<p>i.e., it'll require checking the paths which is error-prone</p>



<a name="178857296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857296">(Oct 23 2019 at 14:12)</a>:</h4>
<p>another option:</p>



<a name="178857336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857336">(Oct 23 2019 at 14:13)</a>:</h4>
<p>decorate the type parameter, or use a fold argument</p>



<a name="178857362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857362">(Oct 23 2019 at 14:13)</a>:</h4>
<p>e.g.,</p>
<div class="codehilite"><pre><span></span><span class="cp">#[derive(Fold)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="cp">#[TypeFamily]</span><span class="w"> </span><span class="n">TF</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">..</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>



<a name="178857373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857373">(Oct 23 2019 at 14:13)</a>:</h4>
<p>although I think the "convention over configuration" option of using distinctive type parameter names might be the easiest/best thing to do here</p>



<a name="178857470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857470">(Oct 23 2019 at 14:14)</a>:</h4>
<p>i.e., maybe we require the type parameter name <code>TF</code> (for a type family) / <code>HTF</code> (for something that has a type family)</p>



<a name="178857502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857502">(Oct 23 2019 at 14:15)</a>:</h4>
<p>Requiring an exact name for the derive to work is kind of brittle though</p>



<a name="178857696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857696">(Oct 23 2019 at 14:17)</a>:</h4>
<p>I think I can make it work for <code>InEnvironment&lt;G: HasTypeFamily&gt;</code>, the macro can then detect the <code>HasTypeFamily</code> bound and generate this:</p>
<div class="codehilite"><pre><span></span>impl&lt;TF: TypeFamily, G&gt; Fold&lt;TF&gt; for InEnvironment&lt;G&gt;
where
    G: HasTypeFamily&lt;TypeFamily = TF&gt; + Fold&lt;TF, Result = G&gt;
{..}
</pre></div>



<a name="178857791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857791">(Oct 23 2019 at 14:18)</a>:</h4>
<p>I'm not 100% sure about all potential edge cases, but as long as we only add to the existing bounds I think it'll work out</p>



<a name="178857967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857967">(Oct 23 2019 at 14:20)</a>:</h4>
<blockquote>
<p>I think I can make it work for <code>InEnvironment&lt;G: HasTypeFamily&gt;</code>, the macro can then detect the <code>HasTypeFamily</code> bound and generate </p>
</blockquote>
<p>I was concerned about things like <code>InEnvironment&lt;G: foo::HasTypeFamily&gt;</code></p>



<a name="178857982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178857982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178857982">(Oct 23 2019 at 14:20)</a>:</h4>
<p>I guess we can make that work by just checking the "tail" element of the path</p>



<a name="178858003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858003">(Oct 23 2019 at 14:20)</a>:</h4>
<p>it is still potentially wrong if you do <code>use HasTypeFamily as HTF</code> but that point "you asked for it"</p>



<a name="178858015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858015">(Oct 23 2019 at 14:21)</a>:</h4>
<p>I'm fine with any such scheme, as long as we document it</p>



<a name="178858125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858125">(Oct 23 2019 at 14:22)</a>:</h4>
<p>I guess I like the idea of scanning the where-clauses and hoping to find exactly one type parameter <code>T</code> that is either:</p>
<ul>
<li>parameterized by <code>*::TypeFamily</code> -- in which case <code>T</code> is the type family for <code>Fold</code></li>
<li>parameterized by <code>*::HasTypeFamily</code> -- in which case the type family for <code>Fold</code> is <code>&lt;T as HasTypeFamily&gt;::TypeFamily</code></li>
</ul>



<a name="178858175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858175">(Oct 23 2019 at 14:23)</a>:</h4>
<blockquote>
<p>For the simpler cases I opted for a <code>#[fold_family(ChalkIr)]</code> attribute on the fold-deriving struct. Not sure if that's the best way, but it seems to work fine</p>
</blockquote>
<p>regarding this:</p>



<a name="178858205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858205">(Oct 23 2019 at 14:23)</a>:</h4>
<p>one thing that is sort of annoying is writing <code>HasTypeFamily</code> impls</p>



<a name="178858210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858210">(Oct 23 2019 at 14:23)</a>:</h4>
<p>maybe we should derive <em>that</em> too ?</p>



<a name="178858223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858223">(Oct 23 2019 at 14:23)</a>:</h4>
<p>using the same rules, perhaps, and perhaps with a procedural macro that lets you hard-code it</p>



<a name="178858233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858233">(Oct 23 2019 at 14:23)</a>:</h4>
<p>in that case, when you derive <code>Fold</code>, we could do</p>



<a name="178858305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858305">(Oct 23 2019 at 14:24)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">impl</span><span class="o">&lt;</span><span class="n">TF</span><span class="p">,</span><span class="w"> </span><span class="p">...</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Fold</span><span class="o">&lt;</span><span class="n">TF</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">...</span><span class="w"></span>
<span class="k">where</span><span class="w"> </span><span class="p">...,</span><span class="w"> </span><span class="n">Self</span>: <span class="nc">HasTypeFamily</span><span class="o">&lt;</span><span class="n">TypeFamily</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">TF</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">TF</span>: <span class="nc">TypeFamily</span><span class="p">,</span><span class="w"></span>
<span class="p">{</span><span class="w"> </span><span class="p">..</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>



<a name="178858317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858317">(Oct 23 2019 at 14:24)</a>:</h4>
<p>i.e., we move the heuristic from <code>derive(Fold)</code> to <code>derive(TypeFamily)</code></p>



<a name="178858351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858351">(Oct 23 2019 at 14:25)</a>:</h4>
<p>(and if you want to write fold for something that doesn't have a type family, you write it by hand; those are the rare cases like <code>Vec</code>, copy types, etc, and we can't derive those anyway)</p>



<a name="178858714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858714">(Oct 23 2019 at 14:29)</a>:</h4>
<p>Hmm, does that work for enums and structs that have no type parameters?</p>



<a name="178858982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178858982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178858982">(Oct 23 2019 at 14:31)</a>:</h4>
<p>But yeah, HasTypeFamily wouldn't be too hard to derive probably. Not sure if that would remove all TypeFamily logic from Fold though</p>



<a name="178859201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178859201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178859201">(Oct 23 2019 at 14:33)</a>:</h4>
<p>I'd like to avoid changing the struct/enum definitions too much while working on the Fold derive macro</p>



<a name="178860655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178860655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178860655">(Oct 23 2019 at 14:46)</a>:</h4>
<blockquote>
<p>Hmm, does that work for enums and structs that have no type parameters?</p>
</blockquote>
<p>do you mean the ones in rust-ir?</p>



<a name="178860766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178860766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178860766">(Oct 23 2019 at 14:47)</a>:</h4>
<p>if so, I think they would require something like</p>
<div class="codehilite"><pre><span></span><span class="cp">#[derive(Fold, ..)]</span><span class="w"></span>
<span class="cp">#[has_type_family(ChalkIr)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">StructDatum</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>


<p>where <code>has_type_family(ChalkIr)</code> generates something like</p>
<div class="codehilite"><pre><span></span><span class="k">impl</span><span class="w"> </span><span class="n">HasTypeFamily</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">StructDatum</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">TypeFamily</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ChalkIr</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>this kills two birds with one stone, since it prevents the need to manually add such an impl</p>



<a name="178860810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178860810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178860810">(Oct 23 2019 at 14:47)</a>:</h4>
<p>if you can do <code>#[derive(HasTypeFamily(ChalkIr), Fold, ..)]</code> that'd be even slicker</p>



<a name="178860874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178860874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178860874">(Oct 23 2019 at 14:48)</a>:</h4>
<p>not sure if that's something we support or not though</p>



<a name="178860913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178860913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178860913">(Oct 23 2019 at 14:48)</a>:</h4>
<p>(the idea would be that <code>#[derive(HasTypeFamily)]</code> requires a suitable type parameter, whereas <code>derive(HasTypeFamily(X))</code> hard-codes to <code>X</code>)</p>



<a name="178861239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178861239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178861239">(Oct 23 2019 at 14:51)</a>:</h4>
<p>Derive arguments like that aren't possible, I think. That's why I had to resort to an extra attribute</p>



<a name="178861319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178861319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178861319">(Oct 23 2019 at 14:52)</a>:</h4>
<p>yeah, ok</p>



<a name="178861398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178861398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178861398">(Oct 23 2019 at 14:53)</a>:</h4>
<p>if you want arguments in all cases I would not use a derive; attribute macros are I believe stable these days so just go for them directly I think</p>



<a name="178861468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/178861468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#178861468">(Oct 23 2019 at 14:53)</a>:</h4>
<p>you don't want them in all cases</p>



<a name="179164765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/179164765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#179164765">(Oct 27 2019 at 10:17)</a>:</h4>
<p><span class="user-mention" data-user-id="125131">@detrumi</span> (warning, I'm hacking on the Fold trait quite a lot in a branch, so I'm making a lot of edits to the derive)</p>



<a name="179171817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/being%20generic%20over%20types/near/179171817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/being.20generic.20over.20types.html#179171817">(Oct 27 2019 at 13:48)</a>:</h4>
<p>Cool, curious to see what you can come up with</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>